package me.green.util;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;


public class ClipboardUtil {

	public static void copy(Clipboard clip, String value) {
		Transferable tText = new StringSelection(value);
		Transferable clearer = new StringSelection("");
		clip.setContents(clearer, null);
		clip.setContents(tText, null);
		System.out.println("RUN");
	}

	public static String paste(Clipboard clip) {
		Transferable tText = clip.getContents(null);
		if (tText != null) {
			if (tText.isDataFlavorSupported(DataFlavor.stringFlavor)) {
				String value = null;
				try {
					value = (String) tText
							.getTransferData(DataFlavor.stringFlavor);
				} catch (UnsupportedFlavorException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
				return value;
			}
		}
		return null;
	}

	public static Clipboard getSystemClipboard() {
		return Toolkit.getDefaultToolkit().getSystemClipboard();
	}

}
